<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-28
 * Time: 17:51
 */

namespace app\api\controller\v1;

use app\api\service\goods\CreateOrderSer;
use app\api\service\goods\DeleteOrderSer;
use app\api\service\goods\RefundOrderSer;
use app\api\service\goods\SendOrderSer;
use think\facade\Request;
use app\api\service\Token;
use app\api\model\GoodsOrder as GoodsOrderModel;

class GoodsOrder
{
    // 创建订单
    public function createOrder()
    {
        $post = Request::post();
        $goodsOrderSer = new CreateOrderSer($post);
        return $goodsOrderSer->entrance();
    }

    // 获取订单列表
    public function getOrderList()
    {
        $uid = Token::getCurrentUid();
        return GoodsOrderModel::where('user_id',$uid)->with('content.img')
            ->order('id desc')
            ->select()->toArray();
    }

    // 获取订单详情
    public function getOrderInfo($id)
    {
        $uid = Token::getCurrentUid();
        return GoodsOrderModel::where('user_id',$uid)
            ->where('id',$id)
            ->with('content.img')
            ->find();
    }

    // 确认收货
    public function updateOrder($order_id)
    {
        $sendOrder = new SendOrderSer($order_id);
        return $sendOrder->entrance();
    }

    // 取消订单
    public function deleteOrder($order_id)
    {
        $deleteOrder = new DeleteOrderSer($order_id);
        return $deleteOrder->entrance();
    }

    // 申请退款
    public function refundOrder($order_id)
    {
       $refundOrder = new RefundOrderSer($order_id);
       return $refundOrder->entrance();
    }
}